﻿using BusinessDB;
using BusinessService.proto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessService
{
    public class ProdConverter
    {
        public ProdClass ToClass(ProdDB prod)
        {
            ProdClass.Builder builder = new ProdClass.Builder();
            builder.SetProdLabel(prod.ProdLabel);
            builder.SetProdSeries(prod.ProdSeries);
            builder.SetAdpClass(prod.AdpClass);
            builder.SetPicFacade(prod.PicFacade);
            return builder.Build();
        }

        public ProdView ToView(ProdDB prod)
        {
            ProdView.Builder builder = new ProdView.Builder();
            builder.SetId(prod.Id.Pid);
            builder.SetPicFacade(prod.PicFacade);
            builder.SetProdSeries(prod.ProdSeries);
            builder.SetProdClass(prod.ProdClass);
            builder.SetProdVersion(prod.ProdVersion);
            builder.SetProdLabel(prod.ProdLabel);
            builder.SetPhySize(prod.PhySize);
            builder.SetAdpClass(prod.AdpClass);
            builder.SetEleLgtPower(prod.EleLgtPower);
            builder.SetAdpColor(prod.AdpColor.ToString());
            builder.SetAdpCri(prod.AdpCri);
            builder.SetOptAngle(prod.OptAngle);
            builder.SetBusMarket(prod.BusMarket);
            return builder.Build();
        }

        public PrimaryProd ToPrimaryProd(ProdDB prod)
        {
            PrimaryProd.Builder builder = new PrimaryProd.Builder();
            builder.SetId(prod.Id.Pid);
            builder.SetProdClass(prod.ProdClass);
            builder.SetProdLabel(prod.ProdLabel);
            builder.SetProdPlace(prod.ProdPlace);
            builder.SetProdSeries(prod.ProdSeries);
            builder.SetProdVersion(prod.ProdVersion);
            builder.SetPhyColor(prod.PhyColor);
            builder.SetPhyDefend(prod.PhyDefend);
            builder.SetPhyImpact(prod.PhyImpact);
            builder.SetPhySize(prod.PhySize);
            builder.SetAdpClass(prod.AdpClass);
            builder.SetAdpColor(prod.AdpColor.ToString());
            builder.SetAdpCri(prod.AdpCri);
            builder.SetEleLgtPower(prod.EleLgtPower);
            builder.SetOptAngle(prod.OptAngle);
            builder.SetProjSetup(prod.ProjSetup);
            builder.SetBusMarket(prod.BusMarket);
            builder.SetPicFacade(prod.PicFacade);
            return builder.Build();
        }

        public Prod ToProd(ProdDB prod)
        {
            Prod.Builder builder = new Prod.Builder();
            builder.SetId(prod.Id.Pid);
            builder.SetProdClass(prod.ProdClass);
            builder.SetProdLabel(prod.ProdLabel);
            builder.SetProdPlace(prod.ProdPlace);
            builder.SetProdSeries(prod.ProdSeries);
            builder.SetProdVersion(prod.ProdVersion);
            builder.SetPhyColor(prod.PhyColor);
            builder.SetPhyDefend(prod.PhyDefend);
            builder.SetPhyImpact(prod.PhyImpact);
            builder.SetPhySize(prod.PhySize);
            builder.SetAdpClass(prod.AdpClass);
            builder.SetAdpColor(prod.AdpColor.ToString());
            builder.SetAdpCri(prod.AdpCri);
            builder.SetEleLgtPower(prod.EleLgtPower);
            builder.SetOptAngle(prod.OptAngle);
            builder.SetProjSetup(prod.ProjSetup);
            builder.SetBusMarket(prod.BusMarket);
            builder.SetPicFacade(prod.PicFacade);

            builder.SetProdOrgin(prod.ProdOrgin);
            builder.SetPhyMaterial(prod.PhyMaterial);
            builder.SetPhyWeight(prod.PhyWeight);
            builder.SetOptExplain(prod.OptExplain);
            builder.SetOptEff(prod.OptEff);
            builder.SetEleShock(prod.EleShock);
            builder.SetEleVoltage(prod.EleVoltage);
            builder.SetEleType(prod.EleType);
            builder.SetEleElecPower(prod.ElePower);
            builder.SetEleAllPower(prod.EleAllPower);
            builder.SetEleCtlType(prod.EleCtlType);
            builder.SetAdpVersion(prod.AdpVersion);
            builder.SetAdpOutput(prod.AdpOutput);
            builder.SetAdpPins(prod.AdpPins);
            builder.SetProjParts(prod.ProjParts);
            builder.SetProjSize(prod.ProjSize);
            builder.SetProjReport(prod.ProjReport);
            builder.SetProjBaikup(prod.ProjBaikup);

            builder.SetBusIn(prod.BusIn);
            builder.SetBusOut(prod.BusOut);
            builder.SetBusExpires(prod.BusExpires);

            builder.SetPicSize(prod.PicSize);
            builder.SetPicGrading(prod.PicGrading);
            builder.SetPicLive(prod.PicLive);

            return builder.Build();
        }

        public ProdDB From(Prod prod)
        {
            ProdDB proddb = new ProdDB();
            proddb.ProdClass = prod.ProdClass;
            proddb.ProdLabel = prod.ProdLabel;
            proddb.ProdPlace = prod.ProdPlace;
            proddb.ProdSeries = prod.ProdSeries;
            proddb.ProdVersion = prod.ProdVersion;
            proddb.PhyColor = prod.PhyColor;
            proddb.PhyDefend = prod.PhyDefend;
            proddb.PhyImpact = prod.PhyImpact;
            proddb.PhySize = prod.PhySize;
            proddb.AdpClass = prod.AdpClass;
            proddb.AdpColor = int.Parse(prod.AdpColor);
            proddb.AdpCri = prod.AdpCri;
            proddb.EleLgtPower = prod.EleLgtPower;
            proddb.OptAngle = prod.OptAngle;
            proddb.ProjSetup = prod.ProjSetup;
            proddb.BusMarket = prod.BusMarket;
            proddb.PicFacade = prod.PicFacade;

            proddb.ProdOrgin = prod.ProdOrgin;
            proddb.PhyMaterial = prod.PhyMaterial;
            proddb.PhyWeight = prod.PhyWeight;
            proddb.OptExplain = prod.OptExplain;
            proddb.OptEff = prod.OptEff;
            proddb.EleShock = prod.EleShock;
            proddb.EleVoltage = prod.EleVoltage;
            proddb.EleType = prod.EleType;
            proddb.ElePower = prod.EleElecPower;
            proddb.EleAllPower = prod.EleAllPower;
            proddb.EleCtlType = prod.EleCtlType;
            proddb.AdpVersion = prod.AdpVersion;
            proddb.AdpOutput = prod.AdpOutput;
            proddb.AdpPins = prod.AdpPins;
            proddb.ProjParts = prod.ProjParts;
            proddb.ProjSize = prod.ProjSize;
            proddb.ProjReport = prod.ProjReport;
            proddb.ProjBaikup = prod.ProjBaikup;

            proddb.BusIn = prod.BusIn;
            proddb.BusOut = prod.BusOut;
            proddb.BusExpires = prod.BusExpires;

            return proddb;


            //builder.SetPicSize(prod.PicSize);
            //builder.SetPicGrading(prod.PicGrading);
            //builder.SetPicLive(prod.PicLive);

        }
    }

    public class UserConverter
    {
        public User To(UserDB user)
        {
            User.Builder builder = new User.Builder();
            builder.SetId(user.Id.Pid);
            builder.SetName(user.Name);
            builder.SetPassword(user.Pwd);
            builder.SetRoleType(user.RoleType);
            return builder.Build();
        }

        public UserDB From(User user)
        {
            return new UserDB
            {
                Name = user.Name,
                Pwd = user.Password,
                RoleType = user.RoleType
            };
        }
    }
}
